import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
// 引入按需加载插件
import vitePluginImp from 'vite-plugin-imp'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer')
      }
    },
    plugins: [
      react(),
      vitePluginImp({
        libList: [
          {
            libName: '@arco-design/web-react',
            style: (name) => {
              return [
                // 加载框架的主要样式文件 index.less
                '@arco-design/web-react/lib/style/index.less',
                // 根据name值按需加载相关组件样式
                `@arco-design/web-react/lib/${name}/style/index.less`
              ]
            }
          }
        ]
      })
    ],
    css: {
      preprocessorOptions: {
        less: {
          // 支持内联 JavaScript
          javascriptEnabled: true
        }
      }
    }
  }
})
